// 某一赛项参赛队伍，及其参赛人员表格
const { Model, DataTypes } = require('sequelize');

const sequelize = require('./database');
const User = require('./user');
const TeamGroup = require('./teamgroup');
const Project = require('./project');
const Match = require('./match');
// 参赛队伍报名表，一只参赛队伍值对应一个赛项，一个赛项有多个参赛队报名。一个团队有多个参赛队
class ProjectTeam extends Model { }

ProjectTeam.init({
  projectId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: "赛项ID",
    allowNull: false,
    references: {
      model: Project, // 指定关联的模型
      key: 'id'
    }
  },
  teamGroupId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    comment: "赛项队伍ID",
    allowNull: false,
    references: {
      model: TeamGroup, // 指定关联的模型
      key: 'id'
    }
  },
  difficultDeclare: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: "难度申报"
  },
  contentDecalare: {
    type: DataTypes.JSON,
    allowNull: true,
    comment: "内容申报"
  },
  projectTeamScore: {
    type: DataTypes.INTEGER,
    comment: "赛项队伍比赛成绩",
    allowNull: true,
  },
  userId: {
    type: DataTypes.INTEGER,
    comment: "创建者ID",
    allowNull: false,
    references: {
      model: User, // 指定关联的模型
      key: 'id'
    }
  },
  matchId: {
    type: DataTypes.INTEGER,
    comment: "比赛ID",
    allowNull: false,
    references: {
      model: Match, // 指定关联的模型
      key: 'id'
    }
  }
}, 
{
  sequelize,
  modelName: 'projectteam'
});
ProjectTeam.belongsTo(User, { foreignKey: 'userId' })
ProjectTeam.belongsTo(TeamGroup, { foreignKey: 'teamGroupId' })
ProjectTeam.belongsTo(Project, { foreignKey: 'projectId' })
ProjectTeam.belongsTo(Match, { foreignKey: 'matchId' })
module.exports = ProjectTeam;